package edu.famework.demo5;

public class Order {
    private String orderId;//订单编号
    private double total;//订单总额
    private OrderItem[] items;//保存多个订单，一个订单就是一个OrderItem对象

    public Order(){

    }

    public Order(String orderId){
        this.orderId = orderId;
        this.items = new OrderItem[3];
    }

    public String getOrderId() {
        return orderId;
    }

    public void setOrderId(String orderId) {
        this.orderId = orderId;
    }

    public double getTotal() {
        calTotal();//调用计算机总额的方法，方法如果不调用就没有意义
        return total;
    }

    public void setTotal(double total) {
        this.total = total;
    }

    public OrderItem[] getItems() {
        return items;
    }

    /**
     *将订单项和OrderItem对象添加到数组中
     *
     * @param item
     * @param i
     */
    public void setItems(OrderItem item,int i) {
        this.items[1] = item;
    }

    /**
     * 订单总额：单价*数量
     */
    public void calTotal(){
        double total = 0;//总额
        for (int i = 0; i < items.length; i++) {
            total = items[i].getPprice() * items[i].getNum();
        }
        this.total = total;

    }
}
